package cn.netty.example5.maspack;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.msgpack.MessagePack;

/**
 * MessageToByteEncoder 是netty提供的消息编码器
 *
 * <p>Title: MesgPackEncoder</p>
 * <p>Description:使用MessagePack编码器进行压缩编码</p>
 * @version V1.0
 * @author ZhiPeng_Chen
 * @date: 2018/10/29
 */
public class MsgpackEncoder extends MessageToByteEncoder<Object> {


    @Override
    protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
        MessagePack msgPack = new MessagePack();
        byte[] raw = null;
        raw = msgPack.write(msg);
        out.writeBytes(raw);
    }


}
